package com.itheima.controller;

import com.itheima.common.CommonResult;
import com.itheima.dto.ShoppingCartDto;
import com.itheima.dto.SubShoppingCartDto;
import com.itheima.pojo.ShoppingCart;
import com.itheima.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author YangJiaHao
 */
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public CommonResult add(@RequestBody ShoppingCartDto shoppingCartDto){
        Boolean result = shoppingCartService.add(shoppingCartDto);
        return CommonResult.success(result);
    }

    @GetMapping("/list")
    public CommonResult list(){
        List<ShoppingCart> shoppingCarts = shoppingCartService.list();
        return CommonResult.success(shoppingCarts);
    }

    @DeleteMapping("/clean")
    public CommonResult clean(){
        Boolean result = shoppingCartService.clean();
        return CommonResult.success(result);
    }

    @PostMapping("/sub")
    public CommonResult remove(@RequestBody SubShoppingCartDto dto){
        Boolean result = shoppingCartService.remove(dto);
        return CommonResult.success(result);
    }
}
